import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Form, Row, Col } from 'antd';

import { AjaxTreeSelect, tool } from 'knk';

const FormItem = Form.Item;

class AjaxTreeSelectDemo extends Component {
    constructor(props) {
        super(props);
        this.state = {
            data: {}
        };
    }

    componentDidMount() {
    }

    componentWillUnmount() {
    }
    
    render() {      
        const { getFieldDecorator } = this.props.form;
        return (
            <Form>
                <Row>
                    <Col span={8}>
                        <FormItem
                            label="行业"
                        >
                            {getFieldDecorator('treeData', {
                                initialValue: []
                            })(
                                <AjaxTreeSelect
                                    apiPath={tool.getPath('tree-list')} 
                                    apiMethod = 'POST'
                                    treeName="树列表"
                                    treeValueKey = "industryId"
                                    treeNameKey = "industryName" 
                                    // isCheck = { true }
                                    isSelectParent = { true }
                                    // multiple = { true }
                                   
                                    // 异步加载
                                    // isOnLoad = { true }
                                    /* 非必填， 默认取 treeValueKey
                                    // apiParent = 'industryId'
                                    // apiParentVal = 'industryId' */
                                />
                            )}
                        </FormItem>
                    </Col>
                </Row>
            </Form>
        );
    }
}

AjaxTreeSelectDemo.propTypes = {
    form: PropTypes.object.isRequired,
    onSubmit: PropTypes.func,
    defaultValue: PropTypes.object
};

export default Form.create()(AjaxTreeSelectDemo);